package com.smiier.skin.ui;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import cn.o.app.json.JsonUtil;
import cn.o.app.net.INetTask;
import cn.o.app.net.NetTaskListener;
import cn.o.app.qrcode.QRCodeView;
import cn.o.app.ui.ODialog;
import cn.o.app.ui.OImageView;
import cn.skinapp.R;

import com.lidroid.xutils.BitmapUtils;
import com.smiier.skin.AccountActivity;
import com.smiier.skin.ChooseTemplateActivity;
import com.smiier.skin.CommentActivity;
import com.smiier.skin.DoctorAnswerActivity;
import com.smiier.skin.DoctorProfileEditActivity;
import com.smiier.skin.MyFollowingActivity;
import com.smiier.skin.MyFollowingQuestionActivity;
import com.smiier.skin.PriceSettingActivity;
import com.smiier.skin.ScanActivity;
import com.smiier.skin.SystemActivity;
import com.smiier.skin.TipMessageActivity;
import com.smiier.skin.ChooseTemplateActivity.TemplateAdapter;
import com.smiier.skin.constant.Constant;
import com.smiier.skin.net.AccountGetTask;
import com.smiier.skin.net.TempleAnswerGetListTask;
import com.smiier.skin.net.AccountGetTask.AccountGetRequest;
import com.smiier.skin.net.AccountGetTask.AccountGetResponse;
import com.smiier.skin.net.CounterGetTask;
import com.smiier.skin.net.CounterGetTask.CounterGetRequest;
import com.smiier.skin.net.CounterGetTask.CounterGetResponse;
import com.smiier.skin.net.DoctorReserveStatusTask;
import com.smiier.skin.net.DoctorReserveStatusTask.DoctorReserveStatusRequest;
import com.smiier.skin.net.DoctorReserveStatusTask.DoctorReserveStatusResponse;
import com.smiier.skin.net.QuestionGetListTask;
import com.smiier.skin.net.QuestionGetListTask.QuestionGetListRequest;
import com.smiier.skin.net.QuestionGetListTask.QuestionGetListResponse;
import com.smiier.skin.net.TempleAnswerGetListTask.TempleAnswerGetListRequest;
import com.smiier.skin.net.TempleAnswerGetListTask.TempleAnswerGetListResponse;
import com.smiier.skin.net.entity.User;
import com.smiier.skin.util.GlobalFormat;
import com.smiier.skin.util.GlobalSettings;
import com.smiier.skin.utils.CommonUtility;
import com.smiier.skin.utils.DBUtil;
import com.smiier.skin.vo.TipMessageVo;

public class PersonalDoctorView extends BasicStateView implements
		View.OnClickListener {

	protected View rl_profile;
	protected View mYueView;
	protected View mTipMsgView;
	protected View mPriceSettingView;
	protected View mTemplateManageView;
	protected View mMyAnswerView;
	protected View mMyGuanZhuView;
	protected View mMyCommentsView;

	protected OImageView img_doctor_icon;
	protected TextView text_doctor_name;
	protected TextView text_doctor_level;
	protected TextView text_doctor_profile;
	protected TextView text_yue_value;
	protected TextView text_my_answer_value;
	protected TextView text_my_guanzhu_value;// 我的关注
	protected TextView itemview_template_manage_value;//解答模板管理
	protected View mSystemSettingView;
	protected TextView text_my_comments_value;
	protected TextView text_doctor_zizhi;
	protected TextView text_doctor_zhuye;
	protected View view_doctor_qr;
	private ODialog mVarcardDialog;
	protected BitmapUtils mBitmapUtils;
	private View mShouCang;
	private TextView mShouCangValue;
	private String mAnswerFinished;
	protected Drawable mCertDrawable;
	
	private ImageView chating_num_img;
	
	
	private static boolean shenhe = false;
	
	private static String chatNum = new String();
	
	TextView mNotifyNum;
	TextView mPrice;

	public PersonalDoctorView(Context context) {
		super(context);
	}

	public PersonalDoctorView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public PersonalDoctorView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public void onCreate() {
		super.onCreate();
		setContentView(R.layout.view_personal_doctor);
		
		Log.i("testooo", "PersonalDoctorView");

		mBitmapUtils = new BitmapUtils(getContext());
		mVarcardDialog = new ODialog(getContext());
		mVarcardDialog.setWindowAnimations(R.style.DialogFromTopAnim);
		init();
		setNavTitle("我的");
		setNavRightBtnIcon(R.drawable.ic_vcard);
		back.setVisibility(View.GONE);
		back.setOnClickListener(this);
		text_right.setOnClickListener(this);

		mCertDrawable = this.getContext().getResources()
				.getDrawable(R.drawable.ic_cert);
		mPrice = findViewById(R.id.itemview_price_setting_value, TextView.class);
		rl_profile = findViewById(R.id.rl_profile, View.class);
		if (rl_profile != null) {
			rl_profile.setOnClickListener(this);
		}
		mYueView = findViewById(R.id.view_yue, View.class);
		if (mYueView != null) {
			mYueView.setOnClickListener(this);
		}
		mTipMsgView = findViewById(R.id.view_tip_msg, View.class);
		if (mTipMsgView != null) {
			mTipMsgView.setOnClickListener(this);
		}
		mPriceSettingView = findViewById(R.id.view_price_setting, View.class);
		if (mPriceSettingView != null) {
			mPriceSettingView.setOnClickListener(this);
		}
		
		mNotifyNum = findViewById(R.id.text_tip_msg_num, TextView.class);

		mTemplateManageView = findViewById(R.id.view_template_manage,
				View.class);
		if (mTemplateManageView != null) {
			mTemplateManageView.setOnClickListener(this);
		}
		mMyAnswerView = findViewById(R.id.view_my_answer, View.class);
		if (mMyAnswerView != null) {
			mMyAnswerView.setOnClickListener(this);
		}
		mMyGuanZhuView = findViewById(R.id.view_my_guanzhu, View.class);
		if (mMyGuanZhuView != null) {
			mMyGuanZhuView.setOnClickListener(this);
		}
		mShouCang = findViewById(R.id.view_my_shoucang, View.class);
		if (mShouCang != null) {
			mShouCang.setOnClickListener(this);
		}
		mShouCangValue = (TextView) findViewById(R.id.text_my_shoucang_value);
		mMyCommentsView = findViewById(R.id.view_my_comments, View.class);
		if (mMyCommentsView != null) {
			mMyCommentsView.setOnClickListener(this);
		}
		
		chating_num_img = findViewById(R.id.chating_num_img, ImageView.class);

		img_doctor_icon = findViewById(R.id.img_doctor_icon, OImageView.class);
		text_doctor_name = findViewById(R.id.text_doctor_name, TextView.class);
		text_doctor_profile = findViewById(R.id.text_doctor_profile,
				TextView.class);
		text_doctor_level = findViewById(R.id.text_doctor_level, TextView.class);
		text_yue_value = findViewById(R.id.text_yue_value, TextView.class);
		text_yue_value.setOnClickListener(this);
		text_my_answer_value = findViewById(R.id.text_my_answer_value,
				TextView.class);
		text_doctor_zizhi = (TextView) findViewById(R.id.text_doctor_zizhi);
		text_doctor_zhuye = (TextView) findViewById(R.id.text_doctor_zhuye);
		text_my_guanzhu_value = findViewById(R.id.text_my_guanzhu_value,
				TextView.class);
		itemview_template_manage_value = findViewById(R.id.itemview_template_manage_value,TextView.class);
		mSystemSettingView = findViewById(R.id.view_system_setting, View.class);
		findViewById(R.id.sure_treatment).setOnClickListener(this);
		mSystemSettingView.setOnClickListener(this);
		text_my_comments_value = findViewById(R.id.text_my_comments_value,
				TextView.class);
		
		
		IntentFilter noReadTab = new IntentFilter(Constant.RECIVER_MYIFNO_ITEM_NOREAD);
		getContext().registerReceiver(noReadTabReceiver, noReadTab);
		 
		
		IntentFilter shenhe = new IntentFilter(Constant.RECIVER_MYIFNO_SHENHE);
		getContext().registerReceiver(shenheReceiver, shenhe);
		Log.i("testdoctorpic", "pic:" + GlobalSettings.sUser.Pic);
	}

	@Override
	public boolean onInterceptBackPressed() {
		if (CommonUtility.indexOf((Activity) getContext(), view_doctor_qr) != -1) {
			CommonUtility.removeView((Activity) getContext(), view_doctor_qr,
					R.anim.push_up_out_activity);
			return true;
		}
		return super.onInterceptBackPressed();
	}

	@Override
	public void onResume() {
		super.onResume();
		if (CommonUtility.isNull(GlobalSettings.sUser)) {
			return;
		}
		try {
			text_doctor_name.setText(GlobalSettings.sUser.Name);
			mPrice.setText(GlobalSettings.sUser.Cost + "");
			JSONArray professional = new JSONArray(
					JsonUtil.convert(GlobalSettings.sUser.Professional));
			StringBuilder sb = new StringBuilder();
			sb.append(GlobalSettings.sUser.Hospital);
			sb.append(com.smiier.skin.utils.CommonUtility
					.convertJSONArray2String(professional, ""));
			text_doctor_profile.setText(GlobalSettings.sUser.Hospital);
			text_doctor_level.setText(com.smiier.skin.utils.CommonUtility
					.convertJSONArray2String(professional, ""));
			if (GlobalSettings.sUser.Is_Cert == User.IS_CERT_APPLY) {
				text_doctor_zizhi.setVisibility(View.VISIBLE);
				text_doctor_zizhi.setText("资质审核中...");
				text_doctor_zizhi.setCompoundDrawablesWithIntrinsicBounds(null,
						null, null, null);
				text_doctor_zhuye.setVisibility(View.GONE);
			} else if (GlobalSettings.sUser.Is_Cert == User.IS_CERT_YES) {
				text_doctor_zizhi.setVisibility(View.VISIBLE);
				text_doctor_zizhi.setText("资质认证");
				text_doctor_zizhi.setCompoundDrawablesWithIntrinsicBounds(
						mCertDrawable, null, null, null);
				text_doctor_zhuye.setVisibility(View.GONE);
			} else {
				
				text_doctor_zizhi.setVisibility(View.VISIBLE);
				text_doctor_zizhi.setText("审核未通过");
				text_doctor_zizhi.setCompoundDrawablesWithIntrinsicBounds(
						null, null, null, null);
			}

			// mBitmapUtils.display(img_doctor_icon,
			// GlobalSettings.SERVER_IMG_URL
			// + GlobalSettings.sUser.Pic + Constant.IMG_TH,
			// new OBitmapLoadCallBack<View>());
			CommonUtility.displayHeadImage(img_doctor_icon, mBitmapUtils,
					GlobalSettings.SERVER_IMG_URL + GlobalSettings.sUser.Pic
							+ Constant.IMG_TH, getContext().getResources(),
					GlobalSettings.sUser.Sex);
		} catch (Exception e) {
			e.printStackTrace();
		}

		AccountGetRequest req = new AccountGetRequest();
		req.token = GlobalSettings.sToken;
		AccountGetTask task = new AccountGetTask();
		task.setRequest(req);
		task.addListener(new NetTaskListener<AccountGetTask.AccountGetRequest, AccountGetTask.AccountGetResponse>() {

			@Override
			public void onException(
					INetTask<AccountGetRequest, AccountGetResponse> task,
					Exception e) {

			}

			@Override
			public void onComplete(
					INetTask<AccountGetRequest, AccountGetResponse> task,
					AccountGetResponse response) {
				if (response.ResultCode != 200) {
					return;
				}
				GlobalSettings.sYue = response.Res;
				String totalAccount = GlobalFormat
						.formatCNY(GlobalSettings.sYue);
				text_yue_value.setText(totalAccount + "元");
			}
		});
		add(task);

		// 获取问题，悬赏和关注数量
		CounterGetRequest cReq = new CounterGetRequest();
		cReq.types = new ArrayList<Integer>();
		cReq.types.add(2002);
		cReq.types.add(2003);
		cReq.types.add(2004);
		cReq.types.add(1002);
		cReq.types.add(2006);
		cReq.types.add(2007);
		cReq.types.add(2001);
		cReq.types.add(2008);
		cReq.types.add(2009);
		cReq.types.add(2005);
		cReq.uids = new ArrayList<Long>();
		cReq.uids.add(GlobalSettings.sUid);
		CounterGetTask cTask = new CounterGetTask();
		cTask.setRequest(cReq);
		cTask.addListener(new NetTaskListener<CounterGetTask.CounterGetRequest, CounterGetTask.CounterGetResponse>() {

			@Override
			public void onException(
					INetTask<CounterGetRequest, CounterGetResponse> task,
					Exception e) {

			}

			@Override
			public void onComplete(
					INetTask<CounterGetRequest, CounterGetResponse> task,
					CounterGetResponse response) {
				if (response.ResultCode != 200) {
					return;
				}
				try {
					JSONArray array = new JSONArray(JsonUtil
							.convert(response.Res));
					int guanzhu_num = 0, comment_num = 0;
					String answer_finish = "0", answer_ing = "/0";
					for (int i = 0; i < array.length(); i++) {
						JSONObject oo = array.getJSONObject(i);
						int key = oo.getInt("Key");
						JSONObject value = oo.getJSONArray("Value")
								.getJSONObject(0);
						if (key == 2002) {
							comment_num += value.getInt("Value");
						} else if (key == 2003) {
							comment_num += value.getInt("Value");
						} else if (key == 2004) {
							comment_num += value.getInt("Value");
						} else if (key == 1002) {
							guanzhu_num += value.getInt("Value");
							mShouCangValue.setText(guanzhu_num + "");
						} else if (key == 2007) {
							guanzhu_num += value.getInt("Value");
						} else if (key == 2006) {
							guanzhu_num += value.getInt("Value");
						} else if (key == 2001) {
							answer_finish = "/" + value.getString("Value");
						} else if (key == 2008) {
							answer_ing = value.getString("Value");
						}
					}
					mAnswerFinished = answer_finish;
					// text_my_answer_value.setText(answer_ing + answer_finish);
					text_my_guanzhu_value.setText(guanzhu_num + "");
					text_my_comments_value.setText(comment_num + "");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		add(cTask);
		QuestionGetListTask qtask = new QuestionGetListTask();
		QuestionGetListRequest qreq = new QuestionGetListRequest();
		qreq.token = GlobalSettings.sToken;
		qreq.doctor_uid = GlobalSettings.sUid;
		qreq.statuses = new ArrayList<Integer>();
		qreq.statuses.add(2);
		qtask.setRequest(qreq);
		qtask.addListener(new NetTaskListener<QuestionGetListTask.QuestionGetListRequest, QuestionGetListTask.QuestionGetListResponse>() {

			@Override
			public void onComplete(
					INetTask<QuestionGetListRequest, QuestionGetListResponse> task,
					QuestionGetListResponse response) {
				if (response != null && response.ResultCode == 200) {
					text_my_answer_value.setText(response.Res.Count
							+ mAnswerFinished);
					
					chatNum = response.Res.Count
							+ mAnswerFinished;
					
					
					/*Intent intent = new Intent();
				    intent.setAction(Constant.RECIVER_MYIFNO_TAB_NOREAD);
				    intent.putExtra("chating", chating);
				    getContext().sendBroadcast(intent);*/
					

					/*int chating = response.Res.Count;	
				    
					
					if(chating > 0){
						chating_num_img.setVisibility(View.VISIBLE);
						text_my_answer_value.setVisibility(View.GONE);
					}else{
						
						chating_num_img.setVisibility(View.GONE);
						text_my_answer_value.setVisibility(View.VISIBLE);
						text_my_answer_value.setText(response.Res.Count
								+ mAnswerFinished);
					}*/
				}

			}

			@Override
			public void onException(
					INetTask<QuestionGetListRequest, QuestionGetListResponse> task,
					Exception e) {

			}
		});
		add(qtask);
		
		
		
		/**
		 * 模板管理个数
		 * 
		 */
		
		guanlimobanCount();
		
		

	}

	private void guanlimobanCount() {
			TempleAnswerGetListRequest req = new TempleAnswerGetListRequest();
			req.token = GlobalSettings.sToken;
			req.pageSize = 10;
//			req.startID = startID;
			TempleAnswerGetListTask task = new TempleAnswerGetListTask();
			task.setRequest(req);
			task.addListener(new NetTaskListener<TempleAnswerGetListTask.TempleAnswerGetListRequest, TempleAnswerGetListTask.TempleAnswerGetListResponse>() {

				@Override
				public void onException(
						INetTask<TempleAnswerGetListRequest, TempleAnswerGetListResponse> task,
						Exception e) {
					
				}

				@Override
				public void onComplete(
						INetTask<TempleAnswerGetListRequest, TempleAnswerGetListResponse> task,
						TempleAnswerGetListResponse response) {
					if (response.ResultCode != 200) {
						return;
					}
					try {
						JSONArray arr = new JSONArray(JsonUtil
								.convert(response.Res.List));
						
						itemview_template_manage_value.setText(arr.length() + "");
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});
			add(task);
		
	}

	public void onClick(View view) {

		int id = view.getId();
		if (id == R.id.rl_profile) {
			
			Intent intent = new Intent();
			
			intent.setClass(getContext(), DoctorProfileEditActivity.class);
			
			if(shenhe){
				intent.putExtra(Constant.IDENTITY_KEY, true);
			}
			
			/*startActivity(new Intent(getContext(),
					));*/
			getContext().startActivity(intent);
			
			
			
			
		} else if (id == R.id.view_template_manage) {
			startActivity(new Intent(getContext(), ChooseTemplateActivity.class));
		} else if (id == R.id.text_right) {
			if (CommonUtility.isNull(view_doctor_qr)) {
				view_doctor_qr = LayoutInflater.from(getContext()).inflate(
						R.layout.view_qr_code, null);
				View ll_qr_code_root = view_doctor_qr
						.findViewById(R.id.ll_qr_code_root);
				ll_qr_code_root.setOnClickListener(this);
				OImageView img_doctor_icon = (OImageView) view_doctor_qr
						.findViewById(R.id.img_doctor_icon);
				QRCodeView img_user_qr_code = (QRCodeView) view_doctor_qr
						.findViewById(R.id.img_user_qr_code);
				TextView text_doctor_id = (TextView) view_doctor_qr
						.findViewById(R.id.text_doctor_id);
				TextView text_doctor_name = (TextView) view_doctor_qr
						.findViewById(R.id.text_doctor_name);
				ImageView image_certifaction = (ImageView) view_doctor_qr
						.findViewById(R.id.image_certifaction);
				try {
					text_doctor_name.setText(GlobalSettings.sUser.Name);
					text_doctor_id.setText(GlobalSettings.sUser.Nick);
					/*
					 * mBitmapUtils.display(img_doctor_icon,
					 * GlobalSettings.SERVER_IMG_URL + GlobalSettings.sUser.Pic
					 * + Constant.IMG_TH, new OBitmapLoadCallBack<View>());
					 */
					CommonUtility.displayHeadImage(img_doctor_icon,
							mBitmapUtils, GlobalSettings.SERVER_IMG_URL
									+ GlobalSettings.sUser.Pic
									+ Constant.IMG_TH, getContext()
									.getResources(), GlobalSettings.sUser.Sex);
					int is_cert = GlobalSettings.sUser.Is_Cert;
					if (is_cert == 1) {
						image_certifaction.setVisibility(View.VISIBLE);
					} else {
						image_certifaction.setVisibility(View.GONE);
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				img_user_qr_code
						.setText("http://www.pifupro.com/UrlControl/Follow_Set_ADD/"
								+ GlobalSettings.sUser.User_Type
								+ "/"
								+ GlobalSettings.sUser.Uid + "/download.aspx");
				mVarcardDialog.setContentView(view_doctor_qr);
			}
			mVarcardDialog.show();
		} else if (id == R.id.ll_qr_code_root) {
			if (mVarcardDialog != null) {
				mVarcardDialog.dismiss();
			}
		} else if (id == R.id.view_my_answer) {
			startActivity(new Intent(getContext(), DoctorAnswerActivity.class));
		} else if (id == R.id.view_my_guanzhu) {
			String[] values = (String[]) view.getTag();
			Intent intent = new Intent(getContext(), MyFollowingActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY, values);
			startActivity(intent);
		} else if (id == R.id.view_yue) {
			startActivity(new Intent(getContext(), AccountActivity.class));
		} else if (id == R.id.view_system_setting) {
			startActivity(new Intent(getContext(), SystemActivity.class));
		} else if (id == R.id.view_my_comments) {
			try {
				Intent intent = new Intent(getContext(), CommentActivity.class);
				intent.putExtra(Constant.IDENTITY_KEY,
						JsonUtil.convert(GlobalSettings.sUser));
				startActivity(intent);
			} catch (Exception e) {

			}
		} else if (id == R.id.view_price_setting) {
			startActivity(new Intent(getContext(), PriceSettingActivity.class));
		} else if (id == R.id.view_tip_msg) {
			startActivity(new Intent(getContext(), TipMessageActivity.class));
		} else if (id == R.id.view_my_shoucang) {
			startActivity(new Intent(getContext(),
					MyFollowingQuestionActivity.class));
		} else if (id == R.id.sure_treatment) {
			Intent i = new Intent(getContext(), ScanActivity.class);
			i.putExtra(Constant.IDENTITY_KEY_TITLE, true);
			startActivityForResult(i, 0);
		}
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 0 && data != null) {
			String info = data.getStringExtra(Constant.IDENTITY_KEY);
			String[] array = info.split(",");
			if (array != null && array.length > 1) {
				DoctorReserveStatusTask task = new DoctorReserveStatusTask();
				DoctorReserveStatusRequest req = new DoctorReserveStatusRequest();
				req.client_id = array[1];
				req.doctorid = GlobalSettings.sUid + "";
				req.is_ios = 0;
				req.status = "已消费";
				req.reserveid = array[0];
				task.setRequest(req);
				task.addListener(new NetTaskListener<DoctorReserveStatusTask.DoctorReserveStatusRequest, DoctorReserveStatusTask.DoctorReserveStatusResponse>() {

					@Override
					public void onComplete(
							INetTask<DoctorReserveStatusRequest, DoctorReserveStatusResponse> task,
							DoctorReserveStatusResponse response) {
						if (response != null && response.ResultCode == 200) {
							toast("项目已消费");
						}
					}

					@Override
					public void onException(
							INetTask<DoctorReserveStatusRequest, DoctorReserveStatusResponse> task,
							Exception e) {

					}
				});
				add(task);
			}
			// Intent i = new Intent(getContext(), ShengmingActivity.class);
			// i.putExtra(Constant.IDENTITY_KEY_1, info);
			// startActivity(i);
		}
	}
	
	
	
	
	BroadcastReceiver noReadTabReceiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			
			Log.i("testooo", "noReadTabReceiver");
			initMessageNoRead(intent);
		}
	};
	
	
	BroadcastReceiver shenheReceiver = new BroadcastReceiver() {
		
		@Override
		public void onReceive(Context context, Intent intent) {
			
			boolean isTongguo = intent.getBooleanExtra("shenhe", false);
			
			Log.i("testooo", "PersonalDoctorView.isTongguo:"+ isTongguo);
			
			if(isTongguo){
				text_doctor_zizhi.setText("资质认证");
				GlobalSettings.sUser.Is_Cert = User.IS_CERT_YES;
			}else{
				text_doctor_zizhi.setText("审核未通过");
				shenhe = true;
				GlobalSettings.sUser.Is_Cert = User.IS_CERT_NO;
			}
			
		}
	};
	
	
	
	private void initMessageNoRead(Intent intent) {

		DBUtil dbUtil = null;
		if (dbUtil == null) {
			dbUtil = DBUtil.getInstance(getContext());
		}

		ArrayList<TipMessageVo> list = dbUtil.query(TipMessageVo.class);

		int noReadNumber = 0;

		if (!list.isEmpty()) {
			for (int i = 0; i < list.size(); i++) {

				if (list.get(i).readState == 0) {
					noReadNumber++;
				}
			}
		}

		if (noReadNumber > 0) {
			mNotifyNum.setVisibility(View.VISIBLE);
			mNotifyNum.setText(noReadNumber + "");
		} else {
			mNotifyNum.setVisibility(View.GONE);
			mNotifyNum.setText("");
		}
		
		
		if(intent.getBooleanExtra("chat", false)){
			chating_num_img.setVisibility(View.VISIBLE);
			text_my_answer_value.setVisibility(View.GONE);
		}else{
			
			chating_num_img.setVisibility(View.GONE);
			text_my_answer_value.setVisibility(View.VISIBLE);
			text_my_answer_value.setText(chatNum);
			
		}
		
		

	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		CommonUtility.unRegisteReciver((Activity) getContext(),
				noReadTabReceiver);
		CommonUtility.unRegisteReciver((Activity) getContext(),
				shenheReceiver);
	}
}
